<template>
    <div class="">
        <el-container class="form-container" style="">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                    <span>信息</span>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;margin-left:10px" @click="handlerEdit">编辑</el-button>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="handleJob" v-if="hasJobStatus">{{jobButtonText}}</el-button>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="handleRunJob">运行</el-button>
                </div>
                <div >
                   <el-form   ref="form"   :model="form" size="small" label-width="120px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item  label="名称">
                                    {{form.fdName}}
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item  label="任务脚本">
                                    {{form.fdCronExpression}}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item  label="任务状态">
                                    <el-tag>{{form.fdJobStatus}}</el-tag>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item  label="任务组">
                                    {{form.fdJobGroup}}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item  label="Bean名称">
                                    {{form.fdBeanName}}
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item  label="method名称">
                                    {{form.fdMethodName}}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item  label="参数">
                                    {{form.fdParam}}
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item  label="创建时间">
                                    {{form.fdCreateTime|formatDate}}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                            <el-form-item  label="描述">
                                {{form.fdDescription}}
                            </el-form-item>
                            </el-col>
                        </el-row>
                   </el-form>
                </div>
            </el-card>
        </el-container>
    </div>
</template>
<script>
import formUtils from '@/utils/formUtils';
import {view} from '@/components/mixins/form';
export default {
    name: "sysQuartzScheduleJobView",
    components: {
    },
    data() {
        return {
            editUrl:'/sys/job/sys_quartz_schedule_job/edit',
            fetchUrl:'/api/sys/job/sys_quartz_schedule_job',
            form: {
                fdId:'',
                fdCreateTime:'',
                fdName:'',
                fdJobName:'',
                fdJobStatus:'',
                fdJobGroup:'',
                fdCronExpression:'',
                fdDescription:'',
                fdBeanName:'',
                fdMethodName:'',
                fdParam:'',
                fdType:''
            }
        }
    },
    mixins:[view],
    methods: {
        handleJob() {
          if(this.hasJobStatus){
            let url = '';
            if(this.form.fdJobStatus === 'NORMAL'){//暂停任务
              url = '/api/sys/job/sys_quartz_schedule_job/pauseJob';
              this.$fetch(url,{
                jobName:this.form.fdJobName,
                jobGroup:this.form.fdJobGroup
              }).then((res) => {
                  this.initForm();
                  this.$message.success('暂停任务成功');
              });
            }else{//重启任务
              url = '/api/sys/job/sys_quartz_schedule_job/resumeJob';
              this.$fetch(url,{
                jobName:this.form.fdJobName,
                jobGroup:this.form.fdJobGroup
              }).then((res) => {
                  this.initForm();
                  this.$message.success('重启任务成功');
              });
            }
              
          }
        },
        handleRunJob() {
          let url = '/api/sys/job/sys_quartz_schedule_job/runOneJob';
          this.$fetch(url,{
            jobName:this.form.fdJobName,
            jobGroup:this.form.fdJobGroup
          }).then((res) => {
              this.$message.success('运行任务成功');
          });
        }
    },
    computed:{
      hasJobStatus : function(){
        if(formUtils.isNotEmpty(this.form.fdJobStatus)){
            return true;
        }
        return false;
      },
      jobButtonText(){
        if(this.hasJobStatus){
          if(this.form.fdJobStatus === 'NORMAL'){
            return '暂停任务';
          }else{
            return '重启任务';
          }
        }
      }
    }
}
</script>
<style scoped >
@import "~@/assets/css/form_view.css";
</style>